package org.itboys.core.controller.front;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.commons.CommonConstants;
import org.itboys.core.entity.mongo.SundayCompanyInfo;
import org.itboys.core.service.mongo.front.SundayFrontCompanyInfoService;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Auther: 罗尧坤
 * Date: 2018/8/23
 * Description:
 */

@Controller
@RequestMapping("/sunday/small/companyInfo")
@Api(value = "companyInfo", description = "企业信息")
public class SundayFrontCompanyInfoController extends BaseController {
    @Autowired
    private SundayFrontCompanyInfoService companyInfoService;

    @RequestMapping(value = "/select", method = {RequestMethod.POST})
    @ApiOperation(value = "小程序 分页获取企业信息")
    public void select(
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        try {
            List<SundayCompanyInfo> result = companyInfoService.select(request);
            ResponseMessage.success(result);
        } catch (Exception e) {
            String  msg  = CommonConstants.ERROMSG;
            Integer code = CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if (e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")) {
                msg = e.getMessage();
                //token已过期
            } else if (e.getClass().getSimpleName().equalsIgnoreCase("TokenException")) {
                code = CommonConstants.TOKEN_CODE;
                msg = CommonConstants.TOKENMSG;
            } else {
                logger.error("/sunday/small/companyInfo/select----e=" + e.getMessage());
            }
            e.printStackTrace();
            ResponseMessage.error(code, msg);
        }
    }

}
